package conMgr.model.tests;

import static org.junit.Assert.*;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.junit.Test;

import conMgr.model.Conference;
import conMgr.model.Paper;
import conMgr.model.Review;
import conMgr.model.Status;
import conMgr.model.User;
import conMgr.model.UserType;
import conMgr.util.ObservableList;

public class PaperTest {

	@Test
	public void testPaper() throws ParseException {
		
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, "Abstract", "category", "keywords", "text");
		assertNotNull(paper_1.getTitle());
		assertNotNull(paper_1.getConference());
		assertNotNull(paper_1.getAuthor());
		assertNotNull(paper_1.getPaperAbstract());
		assertNotNull(paper_1.getCategories());
		assertNotNull(paper_1.getKeywords());
	}
	
	@Test
	public void testAccept() throws ParseException {
	
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, "Abstract", "category", "keywords","text");
		paper_1.accept();
		assertEquals(Status.ACCEPTED, paper_1.getStatus());
	}
	
	@Test
	public void testReject() throws ParseException {
	
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, "Abstract", "category", "keywords", null);
		paper_1.reject();
		assertEquals(Status.REJECTED, paper_1.getStatus());
	}
	
	@Test
	public void testRecind() throws ParseException {
	
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, "Abstract", "category", "keywords", null);
		paper_1.rescind();
		assertEquals(null, paper_1.getCurrentPaper());
	}
	
	@Test
	public void testRevise() throws ParseException {
	
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, "Abstract", "category", "keywords", null);
		paper_1.revise("new title", "new categories", "new keywords");
		assertEquals("new title", paper_1.getTitle());
		assertEquals("new categories", paper_1.getCategories());
		assertEquals("new keywords", paper_1.getKeywords());
	}
	
	@Test
	public void testAssignSubprogramChair() throws ParseException {
		
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, "Abstract", "category", "keywords", null);
		User user_2 = new User("Mike", "Mike@mail.ru", UserType.SUBPROGRAM_CHAIR);
		paper_1.assignSubprogramChair(user_2);
		assertEquals(user_2, paper_1.getSubprogramChair());
		
	}
	
	@Test
	public void testSubmitToProgramChair() throws ParseException {
		Integer rate = 7;
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, "Abstract", "category", "keywords", null);
		paper_1.submitToProgramChair(rate, "rationale");
		assertEquals(rate, paper_1.getSubprogramChairRating());
		assertEquals("rationale", paper_1.getSubprogramChairRationale());
		assertEquals(Status.RECOMMENDED, paper_1.getStatus());
		
		
	}
	
	@Test
	public void testGetUserReviews() throws ParseException{
		
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		Date date_1	=	(Date)formatter.parse("2012-12-12");
		Date date_2	=	(Date)formatter.parse("2012-12-15");
		Date date_3	=	(Date)formatter.parse("2012-12-17");
		Date date_4	=	(Date)formatter.parse("2012-12-19");
		User user_1 = new User("Bob", "Bob@mail.ru", UserType.REVIEWER);
		Conference conf_1 = new Conference("Conf 1", user_1, date_1	, date_2, date_3, date_4);
		Paper paper_1 = new Paper("Paper 1", user_1, conf_1, "Abstract", "category", "keywords", null);
		Review rev_1 = new Review(user_1,paper_1);
		ObservableList<Review> list = paper_1.getPaperReviews();
		assertNotNull(list);
				
		paper_1.getPaperReviews().add(rev_1);
		assertEquals(2, paper_1.getPaperReviews().size());
		assertEquals(rev_1, paper_1.getPaperReviews().get(0));
		
		
	}
	
	
	
	

}
